﻿using DC2010.Objects.Base;
using DC2010.Objects;
using DC2010.Objects.Data;

namespace DC2010.Conditions
{
    public class C_IsItemInHands : ConditionLogic
    {
        public C_IsItemInHands(ConditionData cd) : base(cd)
        {
            ShortName = "Is item in hands";
            LongName = "Checks if item is in hands.";
        }

        public override bool CheckCondition(BaseObject aInvoker, BaseObject aTarget)
        {
            if ((aInvoker is CreatureData) && (aTarget is ItemData))
            {
                CreatureData c = (CreatureData)aInvoker;
                ItemData i = (ItemData)aTarget;

                ItemData iiLeft = c.L.Possession(CarryLocations.LeftHand);
                ItemData iiRight = c.L.Possession(CarryLocations.RightHand);

                bool bResult = false;

                //check left hand
                if (iiLeft !=null)
                    bResult = iiLeft.InfoId == i.Id;

                if ((!bResult)&&(iiRight!=null))
                    bResult = iiRight.InfoId == i.Id;

                HandleEffects(bResult, aInvoker, aTarget);

                return bResult;
            }

            return false;
        }
    }
}
